package com.wjr.controller;

import com.wjr.entity.MyTank;
import com.wjr.service.MyTankService;
import com.wjr.utils.GetImageUtils;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class MyTankController extends KeyAdapter {
    MyTank myTank;
    MyTankService myTankService;
    public MyTankController(MyTank myTank){
        this.myTank = myTank;
    }

    //监听键盘状态
    @Override
    public void keyPressed(KeyEvent e) {
        getKeyboard(e.getKeyCode());
    }

    public void getKeyboard(int code){
        switch (code){
            case 37:
                myTank.x -=5;
                myTank.setImage_MyTank(GetImageUtils.getImage("images/p1tankL.gif"));
                break;
            case 38:
                myTank.y -=5;
                myTank.setImage_MyTank(GetImageUtils.getImage("images/p1tankU.gif"));
                break;
            case 39:
                myTank.x +=5;
                myTank.setImage_MyTank(GetImageUtils.getImage("images/p1tankR.gif"));
                break;
            case 40:
                myTank.y +=5;
                myTank.setImage_MyTank(GetImageUtils.getImage("images/p1tankD.gif"));
                break;
        }
    }
}
